//
//  loginView.m
//  spotrs
//
//  Created by xu on 16/5/12.
//  Copyright © 2016年 TZ. All rights reserved.
//

#import "loginView.h"
#import "findWordViewController.h"

@implementation loginView
{
    UITextField *passName;
    UITextField *passWord;
}
-(void)creatView
{
    [self setBackgroundColor:RGBCOLOR(246, 247, 248)];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
    [tap addTarget:self action:@selector(hiddenBoard)];
    [self addGestureRecognizer:tap];
    
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(20, 75, SCREEN_WIDTH-40, 100)];
    [backView setBackgroundColor:RGBCOLOR(253, 254, 255)];
    backView.layer.borderWidth = 1;
    backView.layer.borderColor = RGBCOLOR(219 , 221, 221).CGColor;
    backView.layer.masksToBounds = YES;
    backView.layer.cornerRadius = 5;
    [self addSubview:backView];
    
    UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 50, backView.frame.size.width-10, 1)];
    [lineLabel setBackgroundColor:RGBCOLOR(219 , 221, 221)];
    
    passName = [[UITextField alloc] initWithFrame:CGRectMake(8, 5, backView.frame.size.width-16, 40)];
    [passName setPlaceholder:@"用户名／手机号码"];
    [backView addSubview:passName];
    if ([[helpUser sharedInstance] getUserName]) {
        [passName setText:[[helpUser sharedInstance] getUserName]];
    }
    
    passWord = [[UITextField alloc] initWithFrame:CGRectMake(8, 55, backView.frame.size.width-16, 40)];
    [passWord setPlaceholder:@"秘密"];
    [backView addSubview:passWord];
    [backView addSubview:lineLabel];
    
    UIButton *liftBtn = [[UIButton alloc] initWithFrame:CGRectMake(50, 185, 20, 20)];
    [self addSubview:liftBtn];
    
    UILabel *liftLabel = [[UILabel alloc] initWithFrame:CGRectMake(75, 185, 60, 20)];
    [liftLabel setText:@"忘记密码"];
    [liftLabel setFont:[UIFont systemFontOfSize:14]];
    [self addSubview:liftLabel];

    UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-135, 185, 20, 20)];
    [self addSubview:rightBtn];
    
    UILabel *rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-110, 185, 60, 20)];
    [rightLabel setText:@"自动登录"];
    [rightLabel setFont:[UIFont systemFontOfSize:14]];
    [self addSubview:rightLabel];
    
    UIButton *zhuCeBtn = [[UIButton alloc]  initWithFrame:CGRectMake(20, 230, (SCREEN_WIDTH-40-20)/2, 40)];
    [zhuCeBtn setTitle:@"注册" forState:UIControlStateNormal];
     [zhuCeBtn setBackgroundColor:[UIColor redColor]];
    [self addSubview:zhuCeBtn];
    
    UIButton *loginCeBtn = [[UIButton alloc]  initWithFrame:CGRectMake((SCREEN_WIDTH-40-20)/2+20+20, 230, (SCREEN_WIDTH-40-20)/2, 40)];
    [loginCeBtn setBackgroundColor:[UIColor redColor]];
    [loginCeBtn addTarget:self action:@selector(userLogin) forControlEvents:UIControlEventTouchUpInside];
    [loginCeBtn setTitle:@"登录" forState:UIControlStateNormal];
    [self addSubview:loginCeBtn];
    
    UIButton *btn = [[UIButton alloc]  initWithFrame:CGRectMake(SCREEN_WIDTH-100, 280, 80, 20)];
    [btn setTitle:@"忘记密码？" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:12];
    [btn setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(pushFindWord) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    
}
-(void)pushFindWord
{
    findWordViewController *find = [[findWordViewController alloc] init];
    [theApp pushController:find];
}
-(void)userLogin
{
    if (passName.text.length != 11)
    {
        promptAlertView *alert = [[promptAlertView alloc] initWithFrame:self.frame title:@"手机号错误"];
        [alert showAlert];
    }
    else
    {
        helpUser *help = [helpUser sharedInstance];
        help.userName = passName.text;
        [help memoryUserName];
    }
    
}
-(void)hiddenBoard
{
    [passName resignFirstResponder];
    [passWord resignFirstResponder];
}
@end
